<template>
  <div class="home">
    <van-tabs>
      <van-tab title="热映" name="a">
        <div class="movieContent">
          <div class="Popular">
            <h3 class="title">最受好评电影</h3>
            <div class="top-rated-list">
              <Best
                v-for="movie in movieList"
                :key="`movie-${movie.id}`"
                :id="movie.id"
                :img="movie.img"
                :globalReleased="movie.globalReleased"
                :wish="movie.wish"
                :sc="movie.sc"
                :nm="movie.nm"
              ></Best>
            </div>
          </div>
        </div>
        <div class="list-wrap">
          <div class="movie-item"
            v-for="movie in movieList"
            :key="`movie-${movie.id}`"
          >
            <van-card
              :title="movie.nm"
              :thumb="movie.img.replace('w.h', '170.230')"
            >
              <template #desc>
                <p class="score line-ellipsis" v-if="movie.globalReleased && movie.sc !== 0">观众评 <span class="grade">{{movie.sc}}</span></p>
                <p class="score line-ellipsis" v-else-if="movie.sc === 0">暂无评分</p>
                <p class="score line-ellipsis" v-else><span class="grade">{{movie.wish}}</span>人想看</p>
                <p class="actor line-ellipsis">主演: {{movie.star}}</p>
                <p class="show-info line-ellipsis">{{movie.showInfo}}</p>
              </template>
              <template #tags>
                <van-button
                  type="danger"
                  size="small"
                  style="float:right"
                  :to="`/moviedetail?id=${movie.id}`"
                 >
                  购票
                </van-button>
              </template>
            </van-card>
          </div>
        </div>
      </van-tab>
      <van-tab title="影院" name="b">内容 2</van-tab>
      <van-tab title="待映" name="c">内容 3</van-tab>
      <van-tab title="经典电影" name="d">内容 4</van-tab>
    </van-tabs>
    <div class=""></div>
  </div>
</template>

<script>
import Best from '../components/Best'
export default {
  name: 'Home',
  data () {
    return {
      movieList: []
    }
  },
  created () {
    this.$http.getMovieList().then((resp) => {
      console.log(resp)
      const { movieList } = resp.data
      this.movieList = movieList
      console.log(this.movieList)
    })
  },
  components: {
    Best
  }
}
</script>

<style lang="scss" scoped>
.home {
  margin-bottom: 50px;
  flex: 1;
  flex-direction: column;
  background-color: #eee;
  margin-bottom: 50px;
  .movieContent {
    margin-top: 2px;
    background: #fff;
    .Popular {
      box-sizing: border-box;
      padding: 15px;
      .title {
        margin: 0;
        font-size: 14px;
        color: #333;
        margin-bottom: 12px;
      }
      .top-rated-list {
        overflow: scroll;
        white-space: nowrap;
      }
    }
  }
  .list-wrap {
    margin-top: 10px;
    background: #fff;
    .van-card__title {
      font-size: 17px;
      color: #333;
      font-weight: 700;
      padding-right: 5px;
      line-height: 2;
    }
    .score {
      .grade {
        font-weight: 700;
        color: #faaf00;
        font-size: 15px;
      }
    }
  }
}
</style>
